package cn.tedu.store.product.webapi.controller;


import cn.tedu.store.commons.pojo.product.dto.CategoryAttributeTemplateAddNewDTO;
import cn.tedu.store.product.service.ICategoryAttributeTemplateService;
import cn.tedu.store.commons.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 分类与属性模板关系控制器
 *
 * @author RelentlessFlow
 * @version 0.0.1
 */
@Slf4j
@Api(tags = "07.分类与属性模板关系管理")
@RestController
@RequestMapping("/category-attribute-template")
public class CategoryAttributeTemplateController {
    @Autowired
    private ICategoryAttributeTemplateService categoryAttributeTemplateService;

    @ApiOperation("绑定类别与属性模板的关联")
    @ApiOperationSupport(order = 100)
    @PostMapping("/bind")
    public JsonResult<Void> bind(CategoryAttributeTemplateAddNewDTO categoryAttributeTemplateAddNewDTO) {
        log.debug("开始处理【绑定类别与属性模板的关联】的请求，品牌：{}，类别：{}",
                categoryAttributeTemplateAddNewDTO.getCategoryId(),
                categoryAttributeTemplateAddNewDTO.getAttributeTemplateId());
        categoryAttributeTemplateService.bind(categoryAttributeTemplateAddNewDTO.getCategoryId(),
                categoryAttributeTemplateAddNewDTO.getAttributeTemplateId());
        return JsonResult.ok();
    }

    @ApiOperation("解绑类别与属性模板的关联")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "类别与属性模板关联的数据id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/unbind")
    public JsonResult<Void> unbind(@PathVariable Long id) {
        log.debug("开始处理【解绑类别与属性模板的关联】的请求：id={}", id);
        categoryAttributeTemplateService.unbind(id);
        return JsonResult.ok();
    }
}
